package com.jae.service.impl;


import com.jae.mapper.UserRoleMapper;
import com.jae.model.user.User;
import com.jae.model.userRole.UserRole;
import com.jae.model.userRole.UserRoleDTO;
import com.jae.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserRoleServiceImpl extends BaseServiceImpl implements UserRoleService {

	@Autowired
	private UserRoleMapper userRoleMapper;
	
	/**
	* 	获取所有用户角色	
	*/
	@Override
	public List<UserRoleDTO> findAll(Map map) {
		return userRoleMapper.findAll(map);
	}
	
	/**
	* 	获取一条用户角色	
	*/
	@Override
	public UserRoleDTO findOne(Map map) {
		return userRoleMapper.findOne(map);
	}
	
	/**
	* 	根据ID获取用户角色	
	*/
	@Override
	public UserRoleDTO findById(Integer user_id) {
		UserRole userRole = new UserRole();
		userRole.setUser_id(user_id);
	
		return userRoleMapper.findById(userRole);
	}
	
	
	
	/**
	 * 新增用户角色
	 */
	@Override
	public boolean insert(UserRole userRole, User user){
		if(userRoleMapper.insert(userRole)!=1)
			serviceError("插入失败");
		return true;
	}
	
	/**
	 * 修改用户角色
	 */
	@Override
	public boolean update(UserRole userRole, User user){
		if(userRoleMapper.update(userRole)!=1)
			serviceError("修改失败");
		return true;
	}
	
	
	/**
	 * 	逻辑删除用户角色
	 */
	@Override
	public boolean updateDelete(Integer user_id, User user){
		UserRole old=new UserRole();
		//userRole.setLast_updated_by(user.getUser_id());
		//userRole.setLast_updated_date(new Date());
		old.setUser_id(user_id);
		
		if(userRoleMapper.updateDelete(old)!=1)
			serviceError("逻辑删除失败");
		return true;
	}
	
	/**
	 * 	物理删除用户角色
	 */
	@Override
	public boolean delete(Integer user_id){
		UserRole old = new UserRole();
		old.setUser_id(user_id);
		if(userRoleMapper.delete(old)!=1)
			serviceError("删除失败");
		return true;
	}
	
}